package com.ccc.excel.controller;

import com.ccc.excel.service.ExcelTransService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author superC
 * @version 2.0.0
 * @date 2023/11/7
 */

@RestController
@RequestMapping("/trans")
public class ExcelTransController {
    protected static final Logger logger = LoggerFactory.getLogger(ExcelTransController.class);

    @Autowired
    private ExcelTransService excelTransService;

    /**
     * Excel整合2个文件数据后再导出
     *
     * @param file     2个文件，第一个为需要调整数据的文件；第二个文件为需要对比的数据
     * @param response
     * @return
     */
    @PostMapping("/toTrans")
    public void toTrans(MultipartFile[] file, HttpServletResponse response) {
        try {
            excelTransService.toTrans(file, response);
        } catch (Exception e) {
            logger.error("【捕获异常】\r\n异常记录：", e);
        }
    }

}
